import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/* CrawlWriter writes an Object to disk.
 * 
 */

public class ObjectWriter {
		
		ObjectOutputStream oos = null;
		String writePath = new String();
		
		// Constructor, opens up an ObjectOutputStream
		public ObjectWriter(String p) {
			writePath = p;
			try {
				oos = new ObjectOutputStream(new FileOutputStream(writePath));
			} catch (Exception e) {
				System.err.println("ObjectWriter Exception: " + writePath);
				e.printStackTrace();
			}
		}
		
		// Write an object to disk
		public void write(Serializable obj){
			
			try {
				oos.writeObject(obj);
				
			} catch(Exception e) {
				System.err.println("WRITE ERROR");
				e.printStackTrace();
			}
		}
		
		// Close the ObjectOutputStream
		public void close() {
			try {
				oos.flush();
				oos.close();
			} catch (Exception e) {
				System.err.println("ObjectOutputStream Close Exception");
				e.printStackTrace();
			}
		}
	}